package org.reborn.engine.render.util

import javax.media.opengl._
import org.reborn.engine.enums._

import java.nio.Buffer

object GLUtil {
  import GL._
  
  private var meshRenderMethod:Option[RenderMesh] = None;
  
  private val meshRenderers:List[RenderMeshSupport] = 
    List(RenderMeshVertexBufferObject,
         RenderMeshVertexArrayRange,
         RenderMeshVertexArray)
  
  def init(gl:GL2):Unit = {
    val renderSupport = meshRenderers.find(_.supportsMeshRenderMethod(gl))
    if(! renderSupport.isEmpty)
      meshRenderMethod = Some(renderSupport.get.createRenderer);
  } 
  
  def useMeshRendererIfAvailable(gl:GL2,renderMeshSupport:RenderMeshSupport){
    if(renderMeshSupport.supportsMeshRenderMethod(gl))
      meshRenderMethod = Some(renderMeshSupport.createRenderer);
  }
  
  def meshRenderer:RenderMesh = meshRenderMethod.get
  
}
